package com.lightdz.tshirtdz.bll;

import com.lightdz.tshirtdz.model.api.ApiResponse;
import com.lightdz.tshirtdz.model.api.login.ApiLogin;
import com.lightdz.tshirtdz.model.api.login.ApiLoginFail;

import com.lightdz.tshirtdz.utils.LogHelper;
import com.sun.javafx.binding.StringFormatter;
import com.lightdz.tshirtdz.utils.HttpClientHelper;
import javafx.beans.binding.StringExpression;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

/**
 * @ Description：${description}
 * @ Author     ：zbl
 * @ Date       ：Created in 16:54 09/08/2018
 * @ Modified By：
 */
@Repository
public class LoginBll {

    public ApiResponse<String> getLoginResult(String appid, String secret, String js_code, String grant_type) {
        ApiResponse<String> apiResponse=new ApiResponse<>();
        String httpGetStr = null;

        try {
            //微信请求地址
            String url = "https://api.weixin.qq.com/sns/jscode2session?appid=%sappid&secret=%ssecret&js_code=%sjs_code&grant_type=%sgrant_type";
            url = String.format(url, appid, secret, js_code, grant_type);

            StringExpression tempStr = StringFormatter.format(url, appid, secret, js_code, grant_type);
            String tempurl = tempStr.getValue();

            httpGetStr = HttpClientHelper.httpGet(url);
            apiResponse=new ApiResponse<>(httpGetStr);
        } catch (Exception e) {
            e.printStackTrace();

        }

        return apiResponse;

//        //正常返回的JSON数据包
//        {
//            "openid": "OPENID",
//                "session_key": "SESSIONKEY",
//        }
//
////满足UnionID返回条件时，返回的JSON数据包
//        {
//            "openid": "OPENID",
//                "session_key": "SESSIONKEY",
//                "unionid": "UNIONID"
//        }
////错误时返回JSON数据包(示例为Code无效)
//        {
//            "errcode": 40029,
//                "errmsg": "invalid code"
//        }
    }

}
